﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using LUStationery.Controller;
using LUStationery.Model;


public partial class CheckDepartmentInfomation : System.Web.UI.Page
{
    DepartmentControl departcont;
    UsersControl usercont;
    PositionListControl plcont;
    Department depart;
    CollectionPointListControl collectionpointlistcont;
    protected void Page_Load(object sender, EventArgs e)
    {


            string username = ((User)Session["user"]).UserName;

            departcont = new DepartmentControl();
            depart = departcont.getDepartmentByUserName(username);
        if (!IsPostBack)
        {   
            lblDepartmentCode.Text = depart.DeptCode;
            lblDepartmentName.Text = depart.DeptName;

            collectionpointlistcont = new CollectionPointListControl();
            ddlCollectionPoint.DataSource = collectionpointlistcont.getCollectionPoints();
            ddlCollectionPoint.DataTextField = "CollectionpointDesc";
            ddlCollectionPoint.DataValueField = "CollectionpointDesc";
            ddlCollectionPoint.DataBind();

            //plcont = new PositionListControl();
            //ddlPosition.DataSource = plcont.getPositionsByDepartment(depart.DeptCode);
            //ddlPosition.DataTextField = "PositionDesc";
            //ddlPosition.DataValueField = "PositionDesc";
            //ddlPosition.DataBind();

            usercont = new UsersControl();
            ddlRepresentative.DataSource = usercont.getUsersByDepartment(depart.DeptName);
            ddlRepresentative.DataTextField = "UserName";
            ddlRepresentative.DataValueField = "UserName";
            ddlRepresentative.DataBind();
            string selectedUserName = ddlRepresentative.SelectedValue;
            lblStaffID.Text = usercont.getUserByUserName(selectedUserName).StaffID;
            
            
        }

        

    }

    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        string selectedCollectionPoint = ddlCollectionPoint.SelectedValue;
        string selectedUserName = ddlRepresentative.SelectedValue;
        int i=departcont.UpdateDeptInfo(depart,selectedCollectionPoint,selectedUserName);
        if (i > 0) {
            Response.Redirect("CheckDepartmentInfomation.aspx");
        }
    }
    protected void ddlRepresentative_SelectedIndexChanged(object sender, EventArgs e)
    {
        usercont = new UsersControl();
        string selectedUserName = ddlRepresentative.SelectedValue;
        lblStaffID.Text = usercont.getUserByUserName(selectedUserName).StaffID;
    }

}
